local skel = fk.CreateSkill{
  name = "tea__dingshi",
  tags = { Skill.Limited, Skill.AttachedKingdom },
  attached_kingdom = { "jin" }
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__dingshi"] = "定史",
  [":tea__dingshi"] = "晋势力技，限定技，出牌阶段，你可以获得弃牌堆中任意张点数均不同的牌，若你以此法获得了所有点数的牌，你可以任意分配你以此法获得的牌。",
  ["#tea__dingshi-poxi"] = "定史：选择任意张点数各不相同的牌获得",
  ["#tea__dingshi-distribute"] = "定史：你可以任意分配这些牌，未分配的牌默认留给自己",
}
---@type ActiveSkillSpec
local dingshi = {
  anim_type = "drawcard",
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 and #Fk:currentRoom().discard_pile > 0
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local discard_pile = table.simpleClone(room.discard_pile)
    -- table.sort(discard_pile, function (a, b)
    --   return Fk:getCardById(a).number < Fk:getCardById(b).number
    -- end)
    local number_list = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }
    local dict = {}
    for i = 1, 13 do
      dict[i] = {}
      dict[i][1] = number_list[i]
      dict[i][2] = table.filter(discard_pile, function (id)
        return Fk:getCardById(id).number == i
      end)
    end
    local cards = room:askToPoxi(player, {
      poxi_type = skel.name,
      data = dict
    })
    if #cards > 0 then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
      if #cards >= 13 and not player.dead then
        room:askToYiji(player, {
          min_num = 0,
          max_num = 999,
          skill_name = skel.name,
          cards = table.filter(cards, function (id)
            return table.contains(player:getCardIds("h"), id)
          end),
          prompt = "#tea__dingshi-distribute"
        })
      end
    end
  end
}
Fk:addPoxiMethod{
  name = skel.name,
  prompt = function (data, extra_data)
    return "#tea__dingshi-poxi"
  end,
  card_filter = function(to_select, selected, data, extra_data)
    return not table.find(selected, function (id)
      return Fk:getCardById(id).number == Fk:getCardById(to_select).number
    end)
  end,
  feasible = function(selected, data, extra_data)
    return true
  end,
}
skel:addEffect("active", dingshi)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel